package com.ws.haungjia.controller;

import com.ws.haungjia.Bean.Fenlie;
import com.ws.haungjia.Service.FenlieService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@RequestMapping("Fenlie")
public class FenIieController {
    @Autowired
    private FenlieService fenlieService;

    @RequestMapping("chaxun")
    public String cha(Model model){
        List<Fenlie> chaxun = fenlieService.chaxun();
        model.addAttribute("fenlie",chaxun);
        return "WEB-INF/houtai/Fenlie/List";
    }

    @RequestMapping("zengjia")
    public String zengjia(String name , int shunxun){
        Fenlie fenlie = new Fenlie();
        fenlie.setFname(name);
        fenlie.setWeizhi(shunxun);
        int add = fenlieService.add(fenlie);
        if (add > 0){
            return "redirect:chaxun";
        }else {
            return "WEB-INF/houtai/Fenlie/add";
        }
//        List<Fenlie> paichong = fenlieService.paichong(shunxun, name);
//        if (paichong != null){
////            return "WEB-INF/houtai/Fenlie/add";
//        }else {
//        int add = fenlieService.add(fenlie);
//        if (add > 0){
//
//        }
//        }
//        return "WEB-INF/houtai/Fenlie/add";

    }



    @RequestMapping("huixian")
    public String huixian(int id,Model model){
        Fenlie huixian = fenlieService.huixian(id);
        model.addAttribute("fenlie",huixian);
        return "WEB-INF/houtai/Fenlie/xiugai";
    }

    @RequestMapping("xiugai")
    public String xiugai(int id,String name,int shunxun) {
        int xiugai = fenlieService.xiugai(name, shunxun, id);
        if (xiugai > 0) {
            return "redirect:chaxun";
        } else {
            return "WEB-INF/houtai/Fenlie/xiugai";
        }
    }

    @RequestMapping("shan")
    public String shan(int id){
        int shan = fenlieService.shan(id);
        if (shan > 0) {
            return "redirect:chaxun";
        }else {
            return "WEB-INF/houtai/Fenlie/List";
        }
    }

    @RequestMapping("Ftiaozhuan")
    public String Ftiaozhuan(){
        return "WEB-INF/houtai/Fenlie/add";
    }
}
